package com.ruoyi.web.controller.eamp;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.eamp.domain.EampEquipment;
import com.ruoyi.eamp.service.IEampEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 仪器设备Controller
 * 
 * @author ruoyi
 * @date 2024-08-08
 */
@RestController
@RequestMapping("/eamp/equipment")
public class EampEquipmentController extends BaseController
{
    @Autowired
    private IEampEquipmentService eampEquipmentService;

    /**
     * 查询仪器设备列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:equipment:list')")
    @GetMapping("/list")
    public TableDataInfo list(EampEquipment eampEquipment)
    {
        startPage();
        eampEquipment.setDelFlg(1L);
        List<EampEquipment> list = eampEquipmentService.selectEampEquipmentList(eampEquipment);
        return getDataTable(list);
    }

    /**
     * 导出仪器设备列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:equipment:export')")
    @Log(title = "仪器设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EampEquipment eampEquipment)
    {
        List<EampEquipment> list = eampEquipmentService.selectEampEquipmentList(eampEquipment);
        ExcelUtil<EampEquipment> util = new ExcelUtil<EampEquipment>(EampEquipment.class);
        util.exportExcel(response, list, "仪器设备数据");
    }

    /**
     * 获取仪器设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('eamp:equipment:query')")
    @GetMapping(value = "/{equipmentaId}")
    public AjaxResult getInfo(@PathVariable("equipmentaId") Long equipmentaId)
    {
        return success(eampEquipmentService.selectEampEquipmentByEquipmentaId(equipmentaId));
    }

    /**
     * 新增仪器设备
     */
    @PreAuthorize("@ss.hasPermi('eamp:equipment:add')")
    @Log(title = "仪器设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EampEquipment eampEquipment)
    {
        eampEquipment.setCreateDate(new Date());
        SysUser user = SecurityUtils.getLoginUser().getUser();
        eampEquipment.setCreateBy(user.getUserName());
        return toAjax(eampEquipmentService.insertEampEquipment(eampEquipment));
    }

    /**
     * 修改仪器设备
     */
    @PreAuthorize("@ss.hasPermi('eamp:equipment:edit')")
    @Log(title = "仪器设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EampEquipment eampEquipment)
    {
        return toAjax(eampEquipmentService.updateEampEquipment(eampEquipment));
    }

    /**
     * 删除仪器设备
     */
    @PreAuthorize("@ss.hasPermi('eamp:equipment:remove')")
    @Log(title = "仪器设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipmentaIds}")
    public AjaxResult remove(@PathVariable Long[] equipmentaIds)
    {
        return toAjax(eampEquipmentService.deleteEampEquipmentByEquipmentaIds(equipmentaIds));
    }

    /**
     * 出库仪器设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('eamp:equipment:out')")
    @PostMapping(value = "/out")
    public AjaxResult getout(@RequestBody EampEquipment eampEquipment)
    {
        return toAjax(eampEquipmentService.outable(eampEquipment));
    }
}
